
<%--
    Document   : oEstrategico
    Created on : 10/04/2010, 03:05:56 PM
    Author     : LAPTOP01
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://struts.apache.org/tags-bean"  prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="/tags/c" prefix="c"%>
<%@ include file="seguridad.jsp" %>
<script src="scripts/ajax.js" language="JavaScript"></script>
<script src="js/calendar.js" language="javascript"></script>
<script src="js/calendar-es.js" language="javascript"></script>
<script src="js/calendar-setup.js" language="javascript"></script>

<html>
    <script LANGUAGE="JavaScript">




    function MetaFisica(codA,codMA,umA,cantA,tipoA,descA,inimes,finmes,codObjBack,codObjEspBack,descObjBack,descObjEspBack){
        //alert("inimesplanoperativo"+inimes);
        //alert("inimesplanoperativo"+finmes);
        tipoA=tipoA.replace(/^\s*|\s*$/g,"");
         if(tipoA=="N"){
             tipoA="N";
         }
         else{
              tipoA="%25";

         }
        var form = document.getElementById("PEIForm");
        var idObj = document.getElementById("codObj").selectedIndex;
        var codObj = document.PEIForm.codObj.options[idObj].text;
        var idObjE = document.getElementById("codObjEsp").selectedIndex;
        var codObjEsp = document.PEIForm.codObjEsp.options[idObjE].text;
        form.action="PEI.do?dispatch=listarMFisica&umA="+umA+"&cantA="+cantA
            +"&codA="+codA+"&tipoA="+tipoA+"&codObj="+codObj+"&codObjEsp="+codObjEsp+"&codMA="+codMA+"&descA="+descA+"&inimes="+inimes+"&finmes="+finmes+"&coe="+idObjE+"&idObj="+idObj+"&codObjBack="+codObjBack+"&codObjEspBack="+codObjEspBack+"&descObjBack="+descObjBack+"&descObjEspBack="+descObjEspBack;//

        form.method="post";
        form.submit();
    }

    function MetaFinanciera(codA,descA,tot,inimes,finmes,codObjBack,codObjEspBack,descObjBack,descObjEspBack){
      
        var form = document.getElementById("PEIForm");
        var idObj = document.getElementById("codObj").selectedIndex;
        var codObj = document.PEIForm.codObj.options[idObj].text;
        var idObjE = document.getElementById("codObjEsp").selectedIndex;
        var codObjEsp = document.PEIForm.codObjEsp.options[idObjE].text;
        form.action="PEI.do?dispatch=listarMFinanciera&codA="+codA
            +"&codObj="+codObj+"&codObjEsp="+codObjEsp+"&tot="+tot+"&descA="+descA+"&inimes="+inimes+"&finmes="+finmes+
            "&codObjBack="+codObjBack+"&codObjEspBack="+codObjEspBack+
            "&descObjBack="+descObjBack+"&descObjEspBack="+descObjEspBack
            ;
        form.method="post";
        form.submit();
    }

    function tareaActividad(codA,descAct,ppto,inimes,finmes,codObjBack,codObjEspBack,descObjBack,descObjEspBack){

        var form = document.getElementById("PEIForm");

        var idObj = document.getElementById("codObj").selectedIndex;
        var descObj = document.PEIForm.codObj.options[idObj].text;

        var idObjE = document.getElementById("codObjEsp").selectedIndex;
        var descObjEsp = document.PEIForm.codObjEsp.options[idObjE].text;



        form.action="PEI.do?dispatch=listarTareaActividad&idActividad="+codA+"&descOEstrategico="+descObj+"&descOEspecifico="+descObjEsp+"&descActividad="+descAct+"&ppto="+ppto+"&inimes="+inimes+"&finmes="+finmes+"&codObjBack="+codObjBack+"&codObjEspBack="+codObjEspBack+"&descObjBack="+descObjBack+"&descObjEspBack="+descObjEspBack;

        form.method="post";
        form.submit();
    }


    function editarT(codAP,inicio,termino){
        document.getElementById("mantenimiento").style.display="";
        document.getElementById("btnbuscar").style.display="none";
        document.getElementById("opcionPOperativo").value=1;
        document.getElementById("inActPer").value=inicio;
        //alert("inicioeditar"+inicio);
        document.getElementById("finActPer").value=termino;
        //alert("terminoeditar"+termino);
        document.getElementById("codActPer").value=codAP;
        //alert("codAPeditar"+codAP);
    }



    function confirmActionGuardar(){
              if (confirm("Se Guardara los cambios hechos en la pantalla  \n ¿Esta seguro de continuar? "))
                return true;
            else
                return false;
        }


        function validar(){
            if (document.getElementById("inActPer").value==""){
                alert("Ingrese la Fecha de Inicio del Plan perativo Modificado");
                document.getElementById("inActPer").focus();
                return;
            }
            if (document.getElementById("finActPer").value==""){
                alert("Ingrese la Fecha de Fin del Plan perativo Modificado");
                document.getElementById("finActPer").focus();
                return;
            }

            var mydate= new Date()
        var theyear=mydate.getFullYear()+1
        var themonth=mydate.getMonth()+1
        var thetoday=mydate.getDate()
        if(date_diff()<0){
            alert("Fecha final manor que la fecha inicial");
            return;
        }
        var finActPer = document.getElementById("finActPer").value;
        var finActPer = finActPer.substr(3, 2)+"/"+finActPer.substr(0, 2)+"/"+finActPer.substr(6, 4);
        var inActPer = document.getElementById("inActPer").value;
        var inActPer = inActPer.substr(3, 2)+"/"+inActPer.substr(0, 2)+"/"+inActPer.substr(6, 4);
        if(dateWithin('01/01/'+theyear,'12/31/'+theyear,inActPer )==false){
            alert("Fuera del rango de la fecha")
            return;
        }
        if(dateWithin('01/01/'+theyear,'12/31/'+theyear,finActPer )==false){
            alert("Fuera del rango de la fecha")
            return;
        }
        
            insertar();
        }


    function insertar(){
        if (confirmActionGuardar()==false) {
            iniciar();
            return;
        }
    	var codOE=document.getElementById("codObjEsp").value;
        var tipo=document.getElementById("opcionPOperativo").value;
        var codActPer = document.getElementById("codActPer").value;
        var inActPer = document.getElementById("inActPer").value;
        var finActPer = document.getElementById("finActPer").value;
        var idDiv = "divTabla";
        var metodo = "GET";
        var url = "consultasAjax/listarAPermanentePlanOperativoAjax.jsp?inActPer="+inActPer+"&finActPer="+finActPer+"&codOE="+codOE+
        "&codActPer="+codActPer+"&tipo="+tipo;
        var cadenaSalida = "";
        var async = true;
        document.getElementById(idDiv).innerHTML;
        autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
        document.getElementById("opcionPOperativo").value=1;
        document.getElementById("btnbuscar").style.display="";
        document.getElementById("mantenimiento").style.display="none";
    }

    function error(){
        alert("Asignar inicio y fin de fecha");
    }



        function buscar(){
            var codOE = document.getElementById("codObjEsp").value;
            if(codOE==-1){
             var codOE = document.getElementById("codObjEsp").value;
            }

            var tipo=0;
            var codActPer = 0;
            var inActPer = "";
            var finActPer = "";
            var idDiv = "divTabla";
            var metodo = "GET";
            var url = "consultasAjax/listarAPermanentePlanOperativoAjax.jsp?inActPer="+inActPer+"&finActPer="+finActPer+"&codOE="+codOE+
            "&codActPer="+codActPer+"&tipo="+tipo;
            var cadenaSalida = "";
            var async = true;
            document.getElementById(idDiv).innerHTML;
            autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
        }

        function describirog(){
            var idObj = document.getElementById("codObj").selectedIndex;
            var descObj = document.PEIForm.codObj.options[idObj].text;
            document.getElementById("descObj").value=descObj;
        }

        function describiroe(){
            var idObje = document.getElementById("codObjEsp").selectedIndex;
            var descObje = document.PEIForm.codObjEsp.options[idObje].text;
            document.getElementById("descObjEsp").value=descObje;
        }






    function comboOEspecifico(){
            describirog();
            var id = document.getElementById("codObj").value;
            var idDiv = "comboOESpecifico";
            var metodo = "GET";
            var url = "consultasAjax/comboOEspecificoPlanOperativoAjax.jsp?id="+id;
            var cadenaSalida = "";
            var async = true;
            document.getElementById(idDiv).innerHTML;
            autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
        }


        function iniciar(){
            document.getElementById("mantenimiento").style.display="none";
            document.getElementById("codObj").value=document.getElementById("codObj1").value;

            //Ini agregado

            document.getElementById("codObj").value=document.getElementById("codObjBack").value;
            document.getElementById("codObjEsp").value=document.getElementById("codObjEspBack").value;

            //Fin Agregado

            buscar();
            //Ini agregado
            document.getElementById("descObj").value=document.getElementById("descObjBack").value;
            document.getElementById("descObjEsp").value=document.getElementById("descObjEspBack").value;
            //Fin agregado
        }
        function autoCompletarDiv(metodo,url,cadena,async,idDiv)
        {
            if( window.XMLHttpRequest )
                ajax = new XMLHttpRequest();
            else
                ajax = new ActiveXObject("Microsoft.XMLHTTP");
            ELEMENT_DIV = idDiv;
            ajax.onreadystatechange = funcionCallbackVerDiv;
            ajax.open( metodo, url, async);
            ajax.send(cadena);
        }

        function funcionCallbackVerDiv()
        {
            if( ajax.readyState == 4 )
            {
                if( ajax.status == 200 )
                { //alert(ajax.responseText);
                    document.getElementById(ELEMENT_DIV).innerHTML = ajax.responseText;
                }
            }
        }


        function posicioninicial(){
            document.getElementById("inActPer").focus();
        }



        function dateWithin(beginDate,endDate,checkDate) {
	var b,e,c;
	b = Date.parse(beginDate);
	e = Date.parse(endDate);
	c = Date.parse(checkDate);
	if((c <= e && c >= b)) {
		return true;
	}
	return false;
}


    function date_diff()
{
        var inActPer = document.getElementById("inActPer").value;
        var inActPer = inActPer.substr(3, 2)+"/"+inActPer.substr(0, 2)+"/"+inActPer.substr(6, 4);
        var finActPer = document.getElementById("finActPer").value;
        var finActPer = finActPer.substr(3, 2)+"/"+finActPer.substr(0, 2)+"/"+finActPer.substr(6, 4);
        var date1=new Date(inActPer.toString());
        var date2=new Date(finActPer.toString());
        //var date1=new Date('05/13/2010');
        
        //var date2=new Date('05/05/2010');
        var oneDay=1000*60*60*24;
        return Math.ceil((date2.getTime()-date1.getTime())/oneDay);
}






    </script>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link type="text/css" rel="stylesheet" href="lib/css/Style_Font_Text.css" >
        <link type="text/css" rel="stylesheet" href="lib/css/Style_PageTable.css" >
        <link type="text/css" rel="stylesheet" href="lib/css/Style_Index.css" >
        <link rel="stylesheet" type="text/css" media="all" href="lib/css/calendar-win2k-cold-1.css" title="win2k-cold-1" />



        <title>JSP Page</title>
    </head>

    <body onload="iniciar()">
        <center>
            <h1 class="substylo">Plan Operativo</h1>
        </center>
        <div style="overflow: auto; width: 700px; height: 400px">
                        <html:form action="PEI.do?dispatch=ingresarPlanOperativo" styleId="PEIForm">
                            <html:hidden property="opcionPOperativo" styleId="opcionPOperativo" value="1"/>
                            <html:hidden property="codActPer" styleId="codActPer"/>
                           <html:hidden property="codObj1" styleId="codObj1"/>
                           <!--Ini agregado-->
                           <html:hidden property="codObjBack" styleId="codObjBack"/>
                           <html:hidden property="codObjEspBack" styleId="codObjEspBack"/>
                           <html:hidden property="descObjBack" styleId="descObjBack"/>
                           <html:hidden property="descObjEspBack" styleId="descObjEspBack"/>

                           <!--Fin agregado-->
                <table border="0" align="center" cellspacing="0" style="width: 600px">
                                    <tr>
                                        <td style="width: 150px">Objetivo General Estrat&eacute;gico: </td>
                                        <td style="width: 400px">
                                            <html:select  property='codObj' styleId='codObj' onchange='comboOEspecifico()' styleClass="select" style="width: 400px" >
                                                <html:option value='-1'>[--Seleccionar Objetivo General Estrat&eacute;gico--]</html:option>
                                                <html:optionsCollection name='PEIForm' property='listaOEstrategico' value='NUM_CODOBJ_PK' label='TX_DESCOBJ'/>
                                            </html:select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 150px"></td>
                                        <td style="width: 400px">
                                            <html:textarea  styleId="descObj" property="descObj"  rows="10" cols="50" disabled="true" />
                                    </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 150px">Objetivo Espec&iacute;fico Estrat&eacute;gico: </td>
                                        <td style="width: 400px">
                                            <div id="comboOESpecifico">
                                                <html:select  styleId="codObjEsp" property="codObjEsp" styleClass="select" style="width: 400px">
                                                    <html:option value="-1">[--Seleccionar Objetivo Espec&iacute;fico Estrat&eacute;gico--]</html:option>
                                                    <html:optionsCollection name='PEIForm' property='listaOEspecifico' value='NUM_CODOBJESP_PK' label='TX_DESCOBJESP' />
                                                </html:select>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 150px"></td>
                                        <td style="width: 400px">
                                            <html:textarea  styleId="descObjEsp" property="descObjEsp"  rows="10" cols="50" disabled="true" />
                                    </td>
                                    </tr>


                                    <tr id="btnbuscar">
                                        <td colspan="2" align="center"><input type="button" value="Buscar" onclick="buscar()"/></td>
                                    </tr>

                                    </table>
                <br>
                <table border="0" align="center" cellspacing="0" id="mantenimiento">
                              <tr>
                                        <td style="width: 150;">Inicio:</td>
                                        <td style="width: 400;">
                                            <html:text  styleId="inActPer" property="inActPer" maxlength="400" readonly="true"/>
                                        <img src= "images/calendar.gif" alt="" name="trigger" id="trigger" title="Abrir Calendario" />
                                        </td>
<td style="width: 20;">
                            &nbsp;
                        </td>
                                        <td style="width: 150;">T&eacute;rmino:</td>
                                        <td style="width: 400;">
                                            <html:text  styleId="finActPer" property="finActPer" maxlength="400" readonly="true"/>
                                        <img src= "images/calendar.gif" alt="" name="trigger2" id="trigger2" title="Abrir Calendario" />
                                        </td>
                                    </tr>

                                    <tr>
                        <td colspan="5" align="center"><input type="button" value="Grabar" onclick="validar()" class="submit2"/></td>
                                    </tr>



                                </table>
                <br>
                <div id="divTabla" style="width:100%">

                                </div>

                        </html:form>
                <script>
                                Calendar.setup(
                {
                  inputField  : "finActPer",         // ID of the input field
                  ifFormat    : "%d/%m/%Y",    // the date format
                  button      : "trigger2"       // ID of the button
                }
                );
                    Calendar.setup(
                {
                  inputField  : "inActPer",         // ID of the input field
                  ifFormat    : "%d/%m/%Y",    // the date format
                  button      : "trigger"       // ID of the button
                }
                );
                            </script>
        </div>
    </body>
</html>